Skip to content

Fix up event-construction in tests ahead of the Rust event port#19781

Merged
erikjohnston merged 17 commits into
developfrom
erikj/fixup_event_tests
May 15, 2026
Merged

Fix up event-construction in tests ahead of the Rust event port#19781
erikjohnston merged 17 commits into
developfrom
erikj/fixup_event_tests

Conversation

@erikjohnston

@erikjohnston erikjohnston commented May 14, 2026

Copy link
Copy Markdown
Member

When we port the Event class to Rust, the constructor will check for the existence of required fields. To support that, we tidy up the test code where we construct fake events to add all the required fields.

There should be no behavioural changes.

Review commit-by-commit.

Prepare for porting the event class into Rust, where the constructor
strictly validates that all format-required fields (depth, hashes,
origin_server_ts, auth_events, prev_events, ...) are present. Most
tests build minimal dicts that omit these fields because they only
care about the fields the test exercises. Introduce make_test_event
and make_test_pdu_event, which layer format-version-aware defaults
on top of caller-supplied fields so individual tests don't need to
spell out every required key.
@erikjohnston erikjohnston force-pushed the erikj/fixup_event_tests branch from ed2418d to 2bdad53 Compare May 14, 2026 12:41
Switch test sites that build EventBase/PDU instances over to
make_test_event / make_test_pdu_event so they pick up the defaults
the strict (Rust-bound) constructor will require.
…rectly

Some test fixtures construct event/PDU dicts inline rather than via
make_test_event — typically because they then run them through
add_hashes_and_signatures or otherwise depend on the exact dict shape.
Add the format-required fields (depth, hashes, auth_events,
prev_events, ...) inline in those cases so they keep working under
the strict (Rust-bound) constructor.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a test-infrastructure cleanup ahead of porting Event to Rust. The Rust constructor will validate that required event fields are present, so the test suite is being updated to consistently include those fields when fabricating fake events. A new tests/test_utils/event_builders.py module centralizes the defaults, and call sites across the test suite are switched from make_event_from_dict / event_from_pdu_json to the new helpers make_test_event / make_test_pdu_event.

Changes:

  • Add tests/test_utils/event_builders.py providing make_test_event and make_test_pdu_event that layer in room-version-aware required-field defaults (type, sender, content, depth, origin_server_ts, hashes, prev_events, room_id, and auth_events/prev_state_events depending on MSC4242).
  • Migrate ~30 test files to use the new helpers; remove direct imports of make_event_from_dict and event_from_pdu_json in those tests.
  • Update test expectations (e.g. _flatten_dict, prune_event, event field whitelisting) to account for the additional default fields now present on test events.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_utils/event_builders.py New helpers with format-version aware defaults.
tests/test_state.py Switch create_event to make_test_event.
tests/test_event_auth.py Migrate many event constructions to make_test_event.
tests/storage/test_sliding_sync_tables.py Use make_test_event for fake kick event.
tests/storage/test_msc4242_state_dag.py Use make_test_event in _make_event.
tests/storage/test_events.py Use make_test_pdu_event for remote PDU fakes.
tests/storage/databases/main/test_events_worker.py Use make_test_event; persist event.get_dict() JSON.
tests/state/test_v21.py Add hashes default to event dict.
tests/state/test_v2.py Migrate to make_test_event; use keyword room_version.
tests/rest/client/test_third_party_rules.py Add hashes to federation event dict.
tests/rest/client/sliding_sync/test_sliding_sync.py Use make_test_event for remote invite.
tests/push/test_push_rule_evaluator.py Use make_test_event; update _flatten_dict expectations.
tests/push/test_presentable_names.py Replace FrozenEvent with make_test_event; return type widened.
tests/handlers/test_sync.py Use make_test_pdu_event for call invite PDUs.
tests/handlers/test_room_summary.py Use make_test_event for fed invite.
tests/handlers/test_room_policy.py Migrate event constructions to make_test_event.
tests/handlers/test_room_member.py Use make_test_pdu_event for invite events.
tests/handlers/test_federation.py Migrate to make_test_event/make_test_pdu_event.
tests/handlers/test_federation_event.py Migrate event constructions.
tests/federation/transport/test_client.py Add common required fields to parser test inputs.
tests/federation/test_federation_server.py Migrate to new helpers.
tests/federation/test_federation_out_of_band_membership.py Migrate to new helpers.
tests/federation/test_federation_client.py Add depth defaults; dedupe duplicate depth.
tests/federation/test_federation_base.py Add required fields to a test event dict.
tests/events/test_utils.py Switch MockEvent to make_test_event with defaults; update prune_event expectations.
tests/events/test_auto_accept_invites.py Use make_test_pdu_event for invite events.
tests/crypto/test_event_signing.py Migrate to make_test_event.
changelog.d/19781.misc Changelog entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@erikjohnston erikjohnston marked this pull request as ready for review May 14, 2026 13:01
@erikjohnston erikjohnston requested a review from a team as a code owner May 14, 2026 13:01
Comment thread tests/test_utils/event_builders.py
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/events/test_utils.py Outdated
Comment thread tests/federation/transport/test_client.py
This can be replaced with a direct call to `make_test_event`
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/federation/test_federation_base.py Outdated
Comment thread tests/federation/test_federation_client.py Outdated
Comment thread tests/push/test_push_rule_evaluator.py Outdated
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/test_utils/event_builders.py Outdated
Comment thread tests/test_utils/event_builders.py Outdated
@erikjohnston erikjohnston merged commit ff55aff into develop May 15, 2026
40 checks passed
@erikjohnston erikjohnston deleted the erikj/fixup_event_tests branch May 15, 2026 09:12
FrenchGithubUser pushed a commit to famedly/synapse-upstreaming that referenced this pull request Jun 12, 2026
…ent-hq#19781)

When we port the `Event` class to Rust, the constructor will check for
the existence of required fields. To support that, we tidy up the test
code where we construct fake events to add all the required fields.

There should be no behavioural changes.

Review commit-by-commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants